package com.wclass.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.wclass.entity.BaseAppUser;
import com.wclass.mapper.BaseAppUserMapper;
import com.wclass.service.IBaseAppUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 */
@Service
public class BaseAppUserServiceImpl extends ServiceImpl<BaseAppUserMapper, BaseAppUser> implements IBaseAppUserService {



    /**
     * 根据Token值查询对象
     *
     * @param token
     * @return
     */
    @Override
    public BaseAppUser selectByToken(String token) {
        return super.selectOne(new EntityWrapper<BaseAppUser>().eq("token", token));
    }

    @Override
    public List<BaseAppUser> selectByInstitutionId(Integer id) {
        return this.baseMapper.selectByInstitutionId(id);
    }



    @Override
    public List<BaseAppUser> getListByAuditStatus(Integer auditStatus) {
        return this.baseMapper.getListByAuditStatus(auditStatus);
    }


    @Override
    public int updateDisabled(Long id, Integer disabled) {
        return this.baseMapper.updateDisabled(id,disabled);
    }

    @Override
    public BaseAppUser selectOneById(Long id) {
        return super.selectOne(new EntityWrapper<BaseAppUser>().eq("id", id));
    }

    @Override
    public void updataDevideInfo(BaseAppUser userVo, String cid, String deviceToken, String mobileType) {
        if (StringUtils.isNotBlank(cid)) {
            userVo.setCId(cid);
        }
        if (StringUtils.isNotBlank(deviceToken)) {
            userVo.setDeviceToken(deviceToken);
        }
        if (StringUtils.isNotBlank(mobileType)) {
            userVo.setMobileType(mobileType);
        }
        this.baseMapper.updateById(userVo);

    }

    /**
     * 更新用户排行榜
     *
     * @return
     */
    @Override
    public int upRankingNum() {
        return baseMapper.upRankingNum();
    }

    /**
     * 取消用户机构的绑定状态
     * @param id
     */
    @Override
    public int updateUserOrganBind(Long id) {
        return baseMapper.updateUserOrganBind(id);
    }

    /**
     * 更新用户学生数量
     * @param id
     */
    @Override
    public int updateStudentNum(Long id) {
        return baseMapper.updateStudentNum(id);
    }

}
